package logic

import (
	"context"
	"meituan/meituanrpc/meituanrpc"

	"meituan/api/internal/svc"
	"meituan/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RegisterLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisterLogic {
	return &RegisterLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RegisterLogic) Register(req *types.RegisterRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	register, err := l.svcCtx.MeiTuanRpc.Register(l.ctx, &meituanrpc.RegisterRequest{
		Mobile:   req.Mobile,
		Password: req.Password,
		SendSms:  req.SendSms,
		CaptCha:  req.CaptCha,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}

	return &types.Response{
		Message: "注册成功",
		Data:    register,
		Code:    200,
	}, nil
}
